import type { BasicTableColumn } from '@/components/table';
import TableFieldType from '@/components/table/src/types/field-type';
import type { FormSchema } from '@/components/form';
import FormFieldType from '@/components/form/src/types/field-type';

export const columns: BasicTableColumn[] = [
  {
    title: 'userId',
    key: 'userId',
    display: false,
    fieldType: TableFieldType.TEXT,
  },
  {
    title: 'deptId',
    key: 'deptId',
    display: false,
    fieldType: TableFieldType.TEXT,
  },
  {
    title: '账号',
    key: 'userName',
    fieldType: TableFieldType.TEXT,
    fixed: 'left',
  },
  {
    title: '昵称',
    key: 'nickName',
    display: false,
    fieldType: TableFieldType.TEXT,
  },
  {
    title: '类型',
    key: 'userType',
    fieldType: TableFieldType.TEXT,
  },
  {
    title: '邮箱',
    key: 'email',
    fieldType: TableFieldType.TEXT,
    width: 180,
  },
  {
    title: '手机号码',
    key: 'phonenumber',
    fieldType: TableFieldType.TEXT,
    width: 120,
  },
  {
    title: '性别',
    key: 'sex',
    fieldType: TableFieldType.TEXT,
  },
  {
    title: '头像',
    key: 'avatar',
    fieldType: TableFieldType.TEXT,
  },
  {
    title: '状态',
    key: 'status',
    fieldType: TableFieldType.TAG,
    width: 100,
    align: 'center',
    tagOptions: {
      options: [
        {
          label: '正常',
          value: '0',
          type: 'success',
        },
        {
          label: '停用',
          value: '1',
          type: 'error',
        },
      ],
    },
  },
  {
    title: '最后登录IP',
    key: 'loginIp',
    fieldType: TableFieldType.TEXT,
    width: 200,
  },
  {
    title: '最后登录时间',
    key: 'loginDate',
    fieldType: TableFieldType.TEXT,
    width: 200,
  },
  {
    title: '备注',
    key: 'remark',
    fieldType: TableFieldType.TEXT,
  },
];

export const formSchemas: FormSchema[] = [
  {
    field: 'userId',
    component: FormFieldType.INPUT,
    label: 'userId',
    display: false,
  },
  {
    field: 'deptId',
    component: FormFieldType.TREE_SELECT,
    label: '所属部门',
    componentProps: {
      shareDataKey: 'departmentTreeData',
      defaultFirst: true,
    },
  },
  {
    field: 'userName',
    component: FormFieldType.INPUT,
    label: '账号',
    rules: [{ required: true }],
  },
  {
    field: 'nickName',
    component: FormFieldType.INPUT,
    label: '昵称',
    rules: [{ required: true }],
  },
  {
    field: 'userType',
    component: FormFieldType.INPUT,
    label: '类型',
  },
  {
    field: 'email',
    component: FormFieldType.INPUT,
    label: '邮箱',
  },
  {
    field: 'phonenumber',
    component: FormFieldType.INPUT,
    label: '手机号码',
  },
  {
    field: 'sex',
    component: FormFieldType.SELECT,
    label: '性别',
    componentProps: {
      valueField: 'value',
      options: [
        {
          label: '男',
          value: '0',
        },
        {
          label: '女',
          value: '1',
        },
        {
          label: '未知',
          value: '2',
        },
      ],
    },
    defaultValue: '0',
  },
  {
    field: 'status',
    component: FormFieldType.RADIO_GROUP,
    label: '状态',
    componentProps: {
      options: [
        {
          label: '正常',
          value: '0',
        },
        {
          label: '停用',
          value: '1',
        },
      ],
    },
    defaultValue: '0',
  },
  {
    field: 'remark',
    component: FormFieldType.INPUT,
    label: '备注',
    componentProps: {
      type: 'textarea',
    },
    giProps: {
      span: 2,
    },
  },
];

export const searchSchemas: FormSchema[] = [
  {
    field: 'userName',
    component: FormFieldType.INPUT,
    label: '账号',
  },
  {
    field: 'nickName',
    component: FormFieldType.INPUT,
    label: '昵称',
  },
  {
    field: 'phonenumber',
    component: FormFieldType.INPUT,
    label: '手机号码',
  },
];

export const roleColumns: BasicTableColumn[] = [
  {
    title: 'roleId',
    key: 'roleId',
    display: false,
    fieldType: TableFieldType.TEXT,
  },
  {
    title: '角色名称',
    key: 'roleName',
    fieldType: TableFieldType.TEXT,
  },
  {
    title: '角色权限',
    key: 'roleKey',
    fieldType: TableFieldType.TEXT,
  },
  {
    title: '数据范围',
    key: 'dataScope',
    display: false,
    fieldType: TableFieldType.TEXT,
  },
  {
    title: '备注',
    key: 'remark',
    fieldType: TableFieldType.TEXT,
  },
  {
    title: '状态',
    key: 'status',
    fieldType: TableFieldType.BOOLEAN,
    width: 100,
    align: 'center',
    booleanOptions: {
      colorType: value => (value === '0' ? 'success' : 'error'),
    },
  },
  {
    title: '创建时间',
    key: 'createTime',
    fieldType: TableFieldType.TEXT,
  },
];
